/** 自定义的面向方向检测模块
*/

/** 全局变量
*/
;定义左右按键
global __MyFaceDetector_rightKey := "right", __MyFaceDetector_leftKey := "left"
;当前面向方向,默认向右
global __MyFaceDetector_face := __MyFaceDetector_rightKey
;对指定的exe窗口执行方向检测
global __MyFaceDetector_exeTitle := ""

/** 内部函数
*/
;左右按键响应,改变方向
__MyFaceDetector_onLeftKey(){
  __MyFaceDetector_face := __MyFaceDetector_leftKey
}
__MyFaceDetector_onRightKey(){
  __MyFaceDetector_face := __MyFaceDetector_rightKey
}

/** 导出函数
*/
;安装方向检测模块,指定exe,还有左右按键定义
MyFaceDetector_setup(exeTitle, rightKey := "right", leftKey := "left"){
  local title := "ahk_exe " . exeTitle
  
  __MyFaceDetector_rightKey := rightKey
  __MyFaceDetector_leftKey := leftKey
  Hotkey, IfWinActive, %title%
  Hotkey, ~%__MyFaceDetector_leftKey%, __MyFaceDetector_onLeftKey
  Hotkey, ~%__MyFaceDetector_rightKey%, __MyFaceDetector_onRightKey
  Hotkey, IfWinActive
}

;获取当前面向方向
MyFaceDetector_getFace(){
  return __MyFaceDetector_face
}